/*
 * TNetworkAccessManager.h
 *
 *  Created on: 2012-10-30
 *      Author: minhua
 */

#ifndef TNETWORKACCESSMANAGER_H_
#define TNETWORKACCESSMANAGER_H_

#include <QObject>
#include <QHash>
#include <QVariant>
#include <QDomElement>
#include <QNetworkReply>
#include <QMap>
#include <QList>
#include <QMutex>

#include "../model/TSession.h"

#include "../utils/TCriticalSection.h"

class TNetworkAccessManager : public QObject
{
	Q_OBJECT
public:
	TNetworkAccessManager();
	~TNetworkAccessManager();

public:
	 QNetworkReply *post(QNetworkRequest &request, const QByteArray &data);
	 QNetworkReply *post(QNetworkRequest &request, QIODevice *data);
	 static TNetworkAccessManager *instance();
	 void setSession(TSessionPointer session);

signals:
	 void done(QNetworkReply *reply);

private slots:
	void dataDone(QNetworkReply *reply);

private:
	void clearManagerList();

private:
	//QNetworkAccessManager     *_networkManager;
	//QList<QNetworkAccessManager*>  _networkManagerOccupyList;
	QList<QNetworkAccessManager*>  _networkManagerEmptyList;
	TSessionPointer                      _session;
	TCriticalSection               _criticalSection;

};

#endif /* TNETWORKACCESSMANAGER_H_ */
